<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>事件绑定</title>
    <script src="../lib/vue-2.6.12.js"></script>
</head>
<style>
    .box{
        width: 200px;
        height: 100px;
    }
</style>

<body>
    <div id="app">
        <div class="box" :style="{ backgroundColor: rgb }"></div>
        <button @click="change">改变样式</button>
    </div>


    <script>

        const vm = new Vue({
            data: {
                // 红色
                r: 0,
                // 绿色
                g: 0,
                // 蓝色
                b: 0,
                index: 0
            },
            methods: {
                change(){
                    this.index ++
                    if(this.index===1){
                        this.r = 255;
                        this.g = 100;
                        this.b = 0;
                    }else if(this.index===2){
                        this.r = 255;
                        this.g = 255;
                        this.b = 0;
                    }else if(this.index===3){
                        this.r = 255;
                        this.g = 0;
                        this.b = 255;
                        this.index=0;
                    }
                },
            },
            computed: {
                rgb() {
                    return `rgb(${this.r},${this.g},${this.b})`
                }
            }
        }).$mount('#app')
    </script>
</body>
</html>